package com.bluesky.drcp.business.service;

import com.bluesky.drcp.business.Function;
import com.bluesky.drcp.business.FunctionModule;
import com.bluesky.drcp.business.Module;
import com.bluesky.drcp.persistence.dao.FunctionDao;
import com.bluesky.drcp.persistence.dao.FunctionModuleDao;
import com.bluesky.drcp.persistence.dao.ModuleDao;

public class FunctionModuleService {
	private FunctionModuleDao functionModuleDao;

	private FunctionDao functionDao;

	private ModuleDao moduleDao;

	public FunctionModuleDao getFunctionModuleDao() {
		return functionModuleDao;
	}

	public void setFunctionModuleDao(FunctionModuleDao functionModuleDao) {
		this.functionModuleDao = functionModuleDao;
	}

	public String getModuleIdByFunctionId(String id) {
		try {
			FunctionModule o = functionModuleDao.get(id);
			return o.getModuleId();
		} catch (Exception e) {
			return null;
		}
	}

	public boolean isModule(String id) {
		return (getModuleIdByFunctionId(id) != null);

	}

	
	public FunctionDao getFunctionDao() {
		return functionDao;
	}

	public ModuleDao getModuleDao() {
		return moduleDao;
	}

	public void setFunctionDao(FunctionDao functionDao) {
		this.functionDao = functionDao;
	}

	public void setModuleDao(ModuleDao moduleDao) {
		this.moduleDao = moduleDao;
	}

	public Module getModuleByFunctionId(String functionId) {
		try {
			String moduleId = getModuleIdByFunctionId(functionId);
			return moduleDao.get(moduleId);
		} catch (Exception ex) {
			return null;
		}
	}
		
	public void saveOrUpdate(FunctionModule functionModule){
		functionModuleDao.saveOrUpdate(functionModule);
	}
	
	public void delete(String functionId){
		functionModuleDao.delete(functionId);
	}
}
